package com.learn.initbean.lifecycle;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;

/**
 * @author daify
 * @date 2019-03-23 15:59
 */
public class LiftTest {

    public static void main(String[] args) {
        ClassPathResource resource = new ClassPathResource("spring5.xml");
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        reader.loadBeanDefinitions(resource);

        // BeanFactory 容器一定要调用该方法进行 BeanPostProcessor 注册
        factory.addBeanPostProcessor(new LifeCycleBeanTest()); // <1>

        LifeCycleBeanTest lifeCycleBean = (LifeCycleBeanTest) factory.getBean("lifeCycle");
        lifeCycleBean.display();

        System.out.println("方法调用完成，容器开始关闭....");
        // 关闭容器
        factory.destroySingletons();
    }
}
